package com.nineclock.approve.controller;

import com.nineclock.approve.ApproveDefinitionControllerApi;
import com.nineclock.approve.dto.ApproveDefinitionResultDto;
import com.nineclock.approve.dto.ApproveDefinitionSaveDto;
import com.nineclock.approve.dto.ApproveGroupDefinitionDto;
import com.nineclock.approve.service.ApproveDefinitionService;
import com.nineclock.common.entity.Result;
import com.nineclock.common.utils.UUIDUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author 黑马程序员
 * @Company http://www.ithiema.com
 * @Version 1.0
 */
@RestController
@RequestMapping("/approve")
public class ApproveDefinitionController implements ApproveDefinitionControllerApi {

    @Autowired
    ApproveDefinitionService approveDefinitionService;

    @Override
    @GetMapping("/seq")
    public Result<String> seq() {
        return Result.success(UUIDUtils.getUUID());
    }

    @Override
    @GetMapping("/approveGroupDefinition")
    public Result<List<ApproveGroupDefinitionDto>> queryApproveGroupDefinition() {
        List<ApproveGroupDefinitionDto> approveGroupDefinitionDtoList = approveDefinitionService.queryApproveGroupDefinition();
        return Result.success(approveGroupDefinitionDtoList);
    }

    @Override
    @PostMapping("/approveDefinition")
    public Result saveApproveDefinition(@RequestBody ApproveDefinitionSaveDto approveDefinitionSaveDto) {
        approveDefinitionService.saveOrEdit(approveDefinitionSaveDto);
        return Result.success();
    }

    @Override
    @GetMapping("/approveDefinition/{id}")
    public Result<ApproveDefinitionResultDto> queryById(@PathVariable String id) {
        ApproveDefinitionResultDto approveDefinitionResultDto = approveDefinitionService.queryById(id);
        return Result.success(approveDefinitionResultDto);
    }
}
